<!DOCTYPE html>
<html>
  <head>
    <title>Calculator</title>
  </head>
  <body>
    <h1>PHP Math Calculator</h1>
    <p>Input any math expression (parenthesis included)</p>
    <form action="" method="GET">
      <input type="text" name="math_exp" id="math_exp" size="50">
      <input type="submit" value="submit">
    </form>
    <h2>Solution:</h2>
    <?php
    require __DIR__ . '/vendor/autoload.php';
       
    use Parse\MathParser;
    use Parse\ParseException;
    use Exception;
       
    try {
        $exp = MathParser::parse($_GET['math_exp']);
        eval("\$solution = {$exp};");
        echo "{$exp} = {$solution}";
    } catch (ParseException $e1) {
        echo "Invalid Expression!";
    } catch (Exception $e2) {
        echo "Some other error occured!";
    }?>
  </body>
</html>
